﻿using Huirui.Cavan.Domain.Seedwork;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    #region Role

    /// <summary>
    /// Role object for NHibernate mapped table 'Role'.
    /// </summary>
    [Serializable]
    public class Role : Persistent
    {
        #region Member Variables

        protected string _name;
        protected string _description;
        protected bool _isUseDenied;
        protected IList<RoleResource> _roleResources;
        public virtual IList<SysController> Controllers { get; set; }
        public virtual IList<SysAction> Actions { get; set; }

        #endregion

        #region Constructors

        public Role() { }

        public Role(int id, bool isUseDenied)
        {
            this.Id = id;
            this._isUseDenied = isUseDenied;
        }

        public Role(string name, string description, bool isUseDenied, DateTime createDate, DateTime modifyDate, int editUser)
        {
            this._name = name;
            this._description = description;
            this._isUseDenied = isUseDenied;
            this._createDate = createDate;
            this._modifyDate = modifyDate;
            this._editUser = editUser;
        }

        #endregion

        #region Public Properties

        public virtual string Name
        {
            get { return _name; }
            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());
                _name = value;
            }
        }

        public virtual string Description
        {
            get { return _description; }
            set
            {
                if (value != null && value.Length > 200)
                    throw new ArgumentOutOfRangeException("Invalid value for Description", value, value.ToString());
                _description = value;
            }
        }

        public virtual bool IsUseDenied
        {
            get { return _isUseDenied; }
            set { _isUseDenied = value; }
        }

        public virtual IList<RoleResource> RoleResources
        {
            get
            {
                if (_roleResources == null)
                {
                    _roleResources = new List<RoleResource>();
                }
                return _roleResources;
            }
            set { _roleResources = value; }
        }

        #endregion
    }
    #endregion
}